<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script
      crossorigin
      src="https://unpkg.com/react@16/umd/react.development.js"
    ></script>
    <script
      crossorigin
      src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"
    ></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/babel">
      class Index extends React.Component {
        constructor() {
          super();
          this.state = {
            num: 0,
            arr:[
              'a','b','c','d'
            ],
            arr2:[
              'asd','zxc','qwe'
            ]
          };
        }
        handleAdd() {
          const { num } = this.state;

          this.setState({
            num: num + 1,
          });
        }

        handelLose() {
          const { num } = this.state;
          if (num < 1) {
            return;
          }
          this.setState({
            num: num - 1,
          });
        }

        render() {
          const { num,arr,arr2 } = this.state;
          let arr2Dom = [];
          for (let index = 0; index < arr2.length; index++) {
            const element = arr2[index];
            arr2Dom.push(<li key={element}>{element}</li>)
          }

          return (
            <div>
              <h1>{num}</h1>
              <button onClick={this.handleAdd.bind(this)}>add</button>
              <button onClick={this.handelLose.bind(this)}>lose</button>
              <ul>
                  {arr.map(v=><li key={v}>{v}</li>)}
              </ul>
              {arr2Dom}
            </div>
          );
        }
      }

      ReactDOM.render(<Index />, document.getElementById("root"));
    </script>
  </body>
</html>
